package com.fyzk.activity.prize;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fyzk.activity.prize.item.PrizeItemBase;
import com.fyzk.activity.prize.item.PrizeItemFactory;
import com.fyzk.utils.LotteryIDUtils;
import com.tyjc.lottery.R;

public class PrizeSelectItemView extends RelativeLayout {

	private Context mContext;
	private TextView mTxt_period;
	private TextView mTxt_date;
	private TextView mTxt_lotteryName;
	private LinearLayout numLayout;
	private TextView mTxt_jczq;	//显示竞彩足球图片及说明
	private TextView mTxt_jclq;	//显示竞彩篮球图片及说明

	private PrizeItemBase prizeShowItem;

	public PrizeSelectItemView(Context context) {
		this(context, null);
	}

	public PrizeSelectItemView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public PrizeSelectItemView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		View.inflate(mContext, R.layout.layout_prizeselect_item, this);
		initView();
	}

	private void initView() {
		mTxt_period = (TextView) findViewById(R.id.dj_layout_prizeselect_item_txt_peroid);
		mTxt_date = (TextView) findViewById(R.id.dj_layout_prizeselect_item_txt_date);
		mTxt_lotteryName = (TextView) findViewById(R.id.dj_layout_prizeselect_item_txt_lotteryName);
		numLayout = (LinearLayout) findViewById(R.id.dj_layout_prizeselect_item_linear_numball);
		mTxt_jczq = (TextView) findViewById(R.id.dj_layout_prizeselect_item_jczq);
		mTxt_jclq = (TextView) findViewById(R.id.dj_layout_prizeselect_item_jclq);
	}

	/**
	 * 设置view的值
	 * @param info
	 */
	public void setPrizeItemData(InquiryInfo info) {

		prizeShowItem = PrizeItemFactory.getInstance().getPrizeItem(info, numLayout);
		
		if(info.lotteryType == LotteryIDUtils.JZRFSPF_LOTTERY_ID_INT){
			numLayout.setVisibility(View.GONE);
			mTxt_date.setVisibility(View.GONE);
			mTxt_period.setVisibility(View.GONE);
			mTxt_jczq.setVisibility(View.VISIBLE);
			mTxt_jclq.setVisibility(View.GONE);
		}else if(info.lotteryType == LotteryIDUtils.JLSF_LOTTERY_ID_INT){
			numLayout.setVisibility(View.GONE);
			mTxt_date.setVisibility(View.GONE);
			mTxt_period.setVisibility(View.GONE);
			mTxt_jczq.setVisibility(View.GONE);
			mTxt_jclq.setVisibility(View.VISIBLE);
		}else if(info.lotteryType == LotteryIDUtils.DCSPF_LOTTERY_ID_INT){
			numLayout.setVisibility(View.GONE);
			mTxt_date.setVisibility(View.GONE);
			mTxt_period.setVisibility(View.GONE);
			mTxt_jczq.setVisibility(View.VISIBLE);
			mTxt_jclq.setVisibility(View.GONE);
		} else{
			numLayout.setVisibility(View.VISIBLE);
			mTxt_date.setVisibility(View.VISIBLE);
			mTxt_period.setVisibility(View.VISIBLE);
			mTxt_jczq.setVisibility(View.GONE);
			mTxt_jclq.setVisibility(View.GONE);
		}
		
		setPeriod(prizeShowItem.getPeroid());
		setDate(prizeShowItem.getDate());
		setLotteryName(prizeShowItem.getLotteryName());
	}

	private void setLotteryName(String lotteryNameResourse) {
		mTxt_lotteryName.setText(lotteryNameResourse);
	}

	private void setPeriod(String period) {
		StringBuffer period_sb = new StringBuffer();
		period_sb.append(mContext.getString(R.string.text_di_qi, period));
		mTxt_period.setText(period_sb.toString());
	}

	private void setDate(String date) {
		mTxt_date.setText(date);
	}

}
